package com.agency.entity;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.agency.dao.UserDao;

@ManagedBean(name="user")
@SessionScoped
public class User implements java.io.Serializable{

	private String username;
	private String firstName;
	private String lastName;
	private String email;
	private String address;
	private String msg, selectedname;
	
	public User() {
		super();
	}

	public User(String username, String firstName, String lastName, String address, String email) {
		super();
		this.username = username;
		this.firstName = firstName;
		this.lastName = lastName;
		this.address = address;
		this.email = email;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public String getSelectedname() {
		return selectedname;
	}
	public void setSelectedname(String selectedname) {
		this.selectedname = selectedname;
	}
	
	public void saveUser() {
		UserDao dao = new UserDao();
		dao.addUser(this);
		this.msg = "Member Info Saved Successfull!";
		clearAll();
	}
	    public void updateUser() {
	        UserDao dao = new UserDao();
	        dao.updateUser(this);
	        this.msg = "Member Info Update Successfull!";
	        clearAll();
	    }
	    public void deleteUser() {
	        UserDao dao = new UserDao();
	        dao.deleteUser(username);
	        this.msg = "Member Info Delete Successfull!";
	        clearAll();
	    }

	    public List<User> getAllUsers() {
	        List<User> users = new ArrayList<User>();
	        UserDao dao = new UserDao();
	        users = dao.getAllUsers();
	        return users;
	    }

	    public void fullInfo() {
	        UserDao dao = new UserDao();
	        //User ctmr = 
	        List<User> lc = dao.getUserById(selectedname);
	        System.out.println(lc.get(0).firstName);
	        this.username = lc.get(0).username;
	        this.firstName = lc.get(0).firstName;
	        this.lastName = lc.get(0).lastName;
	        this.email = lc.get(0).email;
	    }

	    private void clearAll() {
	        this.firstName = "";
	        this.lastName = "";
	        this.email = "";
	        this.username="";
	    }
}
